package com.vueapi.controller.admin;

import com.vueapi.annotation.OperationLog;
import com.vueapi.constant.CommonEnum;
import com.vueapi.domain.HjComment;
import com.vueapi.domain.dto.CommentSearchDTO;
import com.vueapi.service.HjCommentService;
import com.vueapi.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * @Classname AdminCommentController
 * @Description TODO
 * @Created by 赵宏建
 * @Date 2023/8/3 16:36
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/admin/comment")
public class AdminCommentController {

    @Autowired
    private HjCommentService commentService;

    @GetMapping("/list")
    public ResultUtils list(@RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "10") Integer pageSize,
                            @RequestParam(required = false, defaultValue = "") String commentator,
                            @RequestParam(required = false, defaultValue = "") String email,
                            @RequestParam(required = false, defaultValue = "") String blogId,
                            @RequestParam(required = false, defaultValue = "") String ipSource,
                            @RequestParam(required = false, defaultValue = "") String toUser,
                            @RequestParam(required = false, defaultValue = "") String level,
                            @RequestParam(required = false, defaultValue = "") String status) {
        CommentSearchDTO searchDTO = new CommentSearchDTO();
        searchDTO.setCommentator(commentator);
        searchDTO.setEmail(email);
        if(!Objects.equals(blogId, "")){
            searchDTO.setBlogId(Integer.parseInt(blogId));
        }

        if(!Objects.equals(level, "")){
            searchDTO.setLevel(Integer.parseInt(level));
        }

        if(!Objects.equals(status, "")){
            searchDTO.setStatus(Integer.parseInt(status));
        }
        searchDTO.setIpSource(ipSource);
        searchDTO.setToUser(toUser);
        return commentService.listPage(pageNum, pageSize, searchDTO);
    }

    @OperationLog(name = "删除评论")
    @GetMapping("/delete")
    public ResultUtils delete(@RequestParam String ids) {
        Boolean flag = commentService.commentDeleteByIds(ids);
        if(flag){
            return ResultUtils.success();
        }
        return ResultUtils.fail();
    }

    @OperationLog(name = "审核评论")
    @GetMapping("/auditPass")
    public ResultUtils auditPass(@RequestParam String ids){
        Boolean flag = commentService.auditPass(ids);

        if(flag){
            return ResultUtils.success();
        }
        return ResultUtils.fail();
    }

}
